package org.jeecg.desen.file;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 文件迁移 线程池异步操作处理，主要针对hive dfs 文件迁移
 * */
public class FileHiveDFSExecutor {
    private static final Logger logger = LoggerFactory.getLogger(FileHiveDFSExecutor.class);

    private static int corePoolSize = 10; //核心池的大小（即线程池中的线程数目大于这个参数时，提交的任务会被放进任务缓存队列）
    private static int maximumPoolSize = 50;//线程池最大能容忍的线程数

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 200, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(10000));

    public static void execute(String threadName, Runnable command) {
        if (StringUtils.isEmpty(threadName) || null == command) {
            return;
        }
        logger.info("文件迁移线程池加入线程,名称:" + threadName + " ,time:" + System.currentTimeMillis() + ",当前排队数量:" + executor.getQueue().size());
        executor.execute(command);
    }
}
